{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "402815f5",
   "metadata": {},
   "source": [
    "# 1.元组\n",
    "> 1.概念\n",
    "> 2.创建\n",
    "> 3.一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bb54fc60",
   "metadata": {},
   "source": [
    "# 2.集合\n",
    "> 1.概念\n",
    "> 2.创建\n",
    "> 3.一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e999fce",
   "metadata": {},
   "source": [
    "# 3.字典\n",
    "> 1.概念\n",
    "> 2.创建\n",
    "> 3.一般方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "1d70c2d9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1699873680.9343977"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time \n",
    "time.time()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f558ccd1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 1.第一种创建方法\n",
    "my_tuple1 = 1699873680,100001,\"小明\",18,\"冰岛\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "9114b516",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1699873680, 100001, '小明', 18, '冰岛')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "print(my_tuple1)\n",
    "print(type(my_tuple1))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "56087272",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1699873680, 100001, '小明', 18, '冰岛')\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "my_tuple2 = (1699873680,100001,\"小明\",18,\"冰岛\")\n",
    "print(my_tuple2)\n",
    "print(type(my_tuple2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "c4234f09",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('Jessa', 30, 45.75, [23, 78])\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "source": [
    "# 2.第二种创建元组的方法\n",
    "my_tuple3 = tuple(('Jessa',30,45.75,[23,78]))\n",
    "print(my_tuple3)\n",
    "print(type(my_tuple3))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2fb9743f",
   "metadata": {},
   "source": [
    "# 1.2 元组的一般方法"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "9f73b0ab",
   "metadata": {},
   "source": [
    "* 1.关于序列数据的一般方法均适用于元组\n",
    "> 1.indexing and slicing (索引取值和切片)\n",
    "> 2.in方法查询\n",
    "> 3.len()\n",
    "> 4.for循环遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "7318423e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "45.75"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "72cadecf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(45.75, [23, 78])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3[2:4]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5f0770f4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Jalex' in my_tuple3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "5fec1a03",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Jessa' in my_tuple3"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "be0d1ae5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(my_tuple3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "8aa59642",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Jessa\n",
      "30\n",
      "45.75\n",
      "[23, 78]\n"
     ]
    }
   ],
   "source": [
    "for i in my_tuple3:\n",
    "    print(i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "1e10181c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3.count(45.75)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "86c16ff4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "my_tuple3.index([23,78])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ccbe7d3a",
   "metadata": {},
   "source": [
    "##### 元组不可变！！！！！！"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c1c3eacd",
   "metadata": {},
   "source": [
    "# 2.集合"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "31a8fe20",
   "metadata": {},
   "outputs": [],
   "source": [
    "歌剧社 = {'小明','小红','李华','张三'}\n",
    "街舞社 = {'小明','李鹏','王芳'}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "fc0dfb3a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小明', '小红', '张三', '李华', '李鹏', '王芳'}"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 交集:去重\n",
    "歌剧社.union(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "ae87cad4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小明'}"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 交集:找出重复的项\n",
    "歌剧社.intersection(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "6666ac2f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小红', '张三', '李华'}"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 差集\n",
    "歌剧社.difference(街舞社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "7f97083e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'李鹏', '王芳'}"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "街舞社.difference(歌剧社)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "d215b729",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'小红', '张三', '李华', '李鹏', '王芳'}"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 对称差集\n",
    "歌剧社.symmetric_difference(街舞社)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2b5469c9",
   "metadata": {},
   "source": [
    "# 3.字典(dict)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "29526572",
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "info = {\n",
    "    \"stu2201\":\"Ziqi\",\n",
    "    \"stu2202\":\"XiaoFeng\",\n",
    "    \"stu2203\":\"Liuyu\",\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "05517b79",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'stu2201': 'Ziqi', 'stu2202': 'XiaoFeng', 'stu2203': 'Liuyu'}\n"
     ]
    }
   ],
   "source": [
    "print(info)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "30a00557",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'XiaoFeng'"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info[\"stu2202\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "0918f0a0",
   "metadata": {},
   "outputs": [],
   "source": [
    "info_01 = {\n",
    "    \"stu2201\":[\"Ziqi\",2200001,18,\"女\"],\n",
    "    \"stu2202\":[\"XiaoFeng\",2200002,0,\"男\"],\n",
    "    \"stu2203\":[\"Liuyu\",2200003,19,\"男\"],\n",
    "    }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "55585446",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['XiaoFeng', 2200002, 0, '男']"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "info_01[\"stu2202\"]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "21e00db3",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
